package com.ruoyi.project.jiaqin.newsfollow.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.newsfollow.domain.NewsFollow;
import com.ruoyi.project.jiaqin.newsfollow.service.INewsFollowService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 新闻关注Controller
 * 
 * @author LCL
 * @date 2021-10-22
 */
@Controller
@RequestMapping("/jiaqin/newsfollow")
public class NewsFollowController extends BaseController
{
    private String prefix = "jiaqin/newsfollow";

    @Autowired
    private INewsFollowService newsFollowService;

    @RequiresPermissions("jiaqin:newsfollow:view")
    @GetMapping()
    public String newsfollow()
    {
        return prefix + "/newsfollow";
    }

    /**
     * 查询新闻关注列表
     */
    @RequiresPermissions("jiaqin:newsfollow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewsFollow newsFollow)
    {
        startPage();
        List<NewsFollow> list = newsFollowService.selectNewsFollowList(newsFollow);
        return getDataTable(list);
    }

    /**
     * 导出新闻关注列表
     */
    @RequiresPermissions("jiaqin:newsfollow:export")
    @Log(title = "新闻关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NewsFollow newsFollow)
    {
        List<NewsFollow> list = newsFollowService.selectNewsFollowList(newsFollow);
        ExcelUtil<NewsFollow> util = new ExcelUtil<NewsFollow>(NewsFollow.class);
        return util.exportExcel(list, "newsfollow");
    }

    /**
     * 新增新闻关注
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存新闻关注
     */
    @RequiresPermissions("jiaqin:newsfollow:add")
    @Log(title = "新闻关注", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewsFollow newsFollow)
    {
        return toAjax(newsFollowService.insertNewsFollow(newsFollow));
    }

    /**
     * 修改新闻关注
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        NewsFollow newsFollow = newsFollowService.selectNewsFollowById(id);
        mmap.put("newsFollow", newsFollow);
        return prefix + "/edit";
    }

    /**
     * 修改保存新闻关注
     */
    @RequiresPermissions("jiaqin:newsfollow:edit")
    @Log(title = "新闻关注", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewsFollow newsFollow)
    {
        return toAjax(newsFollowService.updateNewsFollow(newsFollow));
    }

    /**
     * 删除新闻关注
     */
    @RequiresPermissions("jiaqin:newsfollow:remove")
    @Log(title = "新闻关注", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(newsFollowService.deleteNewsFollowByIds(ids));
    }
}
